#pragma once
#include"HashTable.hpp"
template<class K>
struct HashFunc {
	size_t operator()(const K& key) {
		return (size_t)key;
	}
};

template<>
struct HashFunc<string> {
	size_t operator()(const string& s) {
		size_t hash = 0;
		for (auto e : s) {
			hash *= 31;
			hash += e;
		}
		return hash;
	}
};


template<class K,class V,class Hash= HashFunc<K>>
class Unordered_map {
public:
	struct Map_KeyOfT {
		const K& operator()(const pair<K, V>& kv) {
			return kv.first;
		}
	};

	typedef typename HT_Backet::HashTable<K, pair<const K, V>, Map_KeyOfT, Hash>::iterator iterator;
	pair<iterator,bool> insert(const pair<K, V>& kv) {
		return _ht.Insert(kv);
	}

	iterator begin() {
		return _ht.begin();
	}

	iterator end() {
		return _ht.end();
	}

	V& operator[](const K& key) {
		auto it = _ht.Insert(make_pair(key, V()));
		return it.first->second;
	}

	void Debug() {
		_ht.Debug();
	}
private:
	HT_Backet::HashTable<K,pair<const K,V>, Map_KeyOfT, Hash> _ht;
};